import datetime

# 获取时间
now = datetime.datetime.now(tz = None)

#datetime.datetime -> str
now = datetime.datetime.now(tz = None)
print(now.strftime("%Y-%m-%d %H:%M:%S"))

#str -> datetime.datetime
now = now.strftime("%Y-%m-%d %H:%M:%S")
print(datetime.datetime.strptime(now, "%Y-%m-%d %H:%M:%S"))

#datetime.datetime -> timestamp
now = datetime.datetime.now(tz = None)
print(now.timestamp())

#timestamp -> datetime.datetime

ts = now.timestamp()
print(datetime.datetime.fromtimestamp(ts, tz = None))


#封装一个函数`get_date(day_delta)`,如果传入的是`-1`,输出就是字符串日期`2020-01-05`
def get_date(day_delta):

    from datetime import timedelta
    now = datetime.datetime.now(tz=None)
    now = now + timedelta(days = day_delta)

    print(f"{now.strftime('%Y-%m-%d')}")

get_date(-1)